package com.titanrise.crm.environment.orm;

import com.titanrise.crm.config.JdbcConfig;
import com.titanrise.crm.environment.annotation.Autowired;
import com.titanrise.crm.environment.annotation.Component;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

/**
 * @Description:
 * @Author: pront
 * @Time:2024-11-04 16:33
 */
@Component
public class JdbcManager {

    @Autowired
    private JdbcConfig jdbcConfig;

    private Connection conn;

    public Connection getConnection() throws SQLException {
        if (conn == null) {
            this.conn = DriverManager.getConnection(this.jdbcConfig.getJdbcUrl(), this.jdbcConfig.getJdbcUsername(), this.jdbcConfig.getJdbcPassword());
        }
        return conn;
    }

}
